package com.nhii.base.common.baseApp;

import android.app.Activity;
import android.content.Context;

import androidx.appcompat.app.AppCompatDelegate;

import com.alibaba.android.arouter.launcher.ARouter;
import com.jess.arms.base.BaseApplication;
import com.nhii.base.common.R;

import com.scwang.smartrefresh.header.MaterialHeader;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreator;
import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreator;
import com.scwang.smartrefresh.layout.api.DefaultRefreshInitializer;
import com.scwang.smartrefresh.layout.api.RefreshFooter;
import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
import com.scwang.smartrefresh.layout.footer.BallPulseFooter;

import me.jessyan.autosize.AutoSizeConfig;
import me.jessyan.autosize.onAdaptListener;


/**
 * author : Alex
 * e-mail : xys9786@outlook.com
 * date   : 2020/4/1221:21
 * desc   :
 * version: 1.0
 */
public class NanHaoApp extends BaseApplication {

    private static NanHaoApp nanHaoApp;


    // 跟随系统设置，这个是默认的
    static {
        AppCompatDelegate.setDefaultNightMode(
                AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
    }


    //static 代码段可以防止内存泄露
    static {

        //设置全局默认配置（优先级最低，会被其他设置覆盖）
        SmartRefreshLayout.setDefaultRefreshInitializer(new DefaultRefreshInitializer() {
            @Override
            public void initialize(Context context, RefreshLayout layout) {
                layout.setEnableLoadMoreWhenContentNotFull(false);//是否在列表不满一页时候开启上拉加载功能
            }
        });
        //设置全局的Header构建器
        SmartRefreshLayout.setDefaultRefreshHeaderCreator(new DefaultRefreshHeaderCreator() {
            @Override
            public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) {
                layout.setPrimaryColorsId(R.color.public_app_color, android.R.color.white);//全局设置主题颜色
                return new MaterialHeader(context).setShowBezierWave(false);//.setTimeFormat(new DynamicTimeFormat("更新于 %s"));//指定为经典Header，默认是 贝塞尔雷达Header
            }
        });
        //设置全局的Footer构建器
        SmartRefreshLayout.setDefaultRefreshFooterCreator(new DefaultRefreshFooterCreator() {
            @Override
            public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) {
                //指定为经典Footer，默认是 BallPulseFooter

                layout.setEnableAutoLoadMore(false);//是否启用列表惯性滑动到底部时自动加载更多

                return new BallPulseFooter(context).setSpinnerStyle(SpinnerStyle.FixedBehind);
            }
        });
    }

    @Override
    public void onCreate() {
        super.onCreate();
        nanHaoApp = this;

        ARouter.init( this ); // 尽可能早，推荐在Application中初始化

        AutoSizeConfig.getInstance()

             .setCustomFragment(false)

              .setExcludeFontScale(true)

                //屏幕适配监听器
                .setOnAdaptListener(new onAdaptListener() {
                    @Override
                    public void onAdaptBefore(Object target, Activity activity) {
                }

                    @Override
                    public void onAdaptAfter(Object target, Activity activity) {
                    }
                });




    }



    public static NanHaoApp getContext(){

        return nanHaoApp;
    }


}
